<?php

$sysPath = dirname(__FILE__);
if (strpos(get_include_path(), $includePath) === false) {
	set_include_path(get_include_path().PATH_SEPARATOR.$sysPath);
}

function __autoload($className){
	if (!class_exists($className,FALSE)&&file_exists(LS_PATH.'/'.$className.'.php')){
		require_once LS_PATH.'/'.$className.'.php';
	}
}

require_once LS_PATH.'/common.php';
if (file_exists(APP_PATH."/common/function.php")){
	include_once APP_PATH."/common/function.php";
}

class App {
	
	private static $_defaultController = 'Index';
	private static $_defaultAction = 'index';
	
	public static function run(){
		$controller = isset($_REQUEST['mod']) ? $_REQUEST['mod']: self::$_defaultController;
    	$action = isset($_REQUEST['act']) ? $_REQUEST['act']: self::$_defaultAction;
    	
		$strClassName = ucfirst($controller)."Controller";
        
        $controllerPath = APP_PATH."/Controller/".$strClassName.".php";
        if (!file_exists($controllerPath)){
        	die ( "Unfound Controller:{$controller}" );
        } 
        require_once $controllerPath;
        $class = new $strClassName();
        
		if (method_exists($class, $action )) {
			$class->$action();
		} else {
			die ( "Unfound Action:{$action}" );
        }
	}
}